﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MTQ.Model;
using System.Security.Principal;
using System.Web.Mvc;

namespace MTQ.Web.Helpers
{
    public static class SessionHelper
    {
        //private static PosDbContext __context = new PosDbContext();
        public static Base_UserInfo GetCurrentUser(this ControllerBase controller)
        {
            var user = controller.ControllerContext.HttpContext.Session["UserInfo"] as Base_UserInfo;
            return user;
        }

        //public static List<Guid> GetSessionListAction(this ControllerBase controller) {
        //    var user = controller.ControllerContext.HttpContext.Session["listUserAction"] as List<Guid>;
        //    return user;
        //}

        public static List<Guid> GetSessionListMenu(this ControllerBase controller)
        {
            var user = controller.ControllerContext.HttpContext.Session["listUserMenuIds"] as List<Guid>;
            return user;
        }

        //public static void SetCurrentUser(this Controller controller, UserInfo userInfo)
        //{
        //    session["UserInfo"] = userInfo;
        //}
    }
    //[Serializable]
    //public class UserInfo
    //{
    //    public Sys_User User { get; set; }
    //    public List<Sys_Permission> Permissions { get; set; }

    //}

    public class UserIdentity : IIdentity
    {
        public string AuthenticationType
        {
            get
            {
                return "Sql";
            }
        }

        public bool IsAuthenticated
        {
            get
            {
                return !string.IsNullOrEmpty(Name);
            }
        }

        public string Name
        {
            get;
            set;
        }
        public int Id { get; set; }
        public Guid Guid { get; set; }
        public List<string> Permissions { get; set; }

        //public UserIdentity(UserInfo info)
        //{
        //    Name = info.User.Name;
        //    Id = info.User.Id;
        //    Guid = info.User.GUID;
        //    Permissions = info.Permissions.Select(e => e.Name).ToList();
        //}
        public UserIdentity(string name)
        {
            Name = name;
        }
    }
}